<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class model_kasus extends CI_Model{
    var $table      = "tbl_kasus";
    var $table_jk   = "tbl_jenis_kasus";
    var $table_sak  = "tbl_saksi";
    var $tbl_city   = "master_city";
    
    public function __construct()
    {
        parent::__construct();
    }
    
    function get_paged_list($limit = 20, $offset = 0, $order_column='datecreated', $order_type='DSC'){
        if(empty($order_column)||empty($order_type)){
            $this->db->order_by("datecreated",'DESC');	
    	}else{
            $this->db->order_by($order_column,$order_type);
            return $this->db->get($this->table, $limit, $offset);
    	}
    }
    
    function get_all(){
        return $this->db->get($this->table);
    }
    
    function map_grouping_provinsi() {
        $q = $this->db->query(
            "SELECT 
                P.`id_provinsi`,
                P.`lat`,
                P.`long`,
                P.nama_provinsi,COUNT(*) as jumlah 
            FROM `tbl_kasus` as K LEFT 
            JOIN `tbl_provinsi` as P ON K.`id_provinsi` = P.`id_provinsi` 
            GROUP BY K.`id_provinsi`");
        return $q->result();
    }
    
    function save_tata($isi){
        $this->db->insert("tatacara",$isi);
    }
    
    function update_tata($id,$array){
        $this->db->where("idtata",$id);	
        $this->db->update('tatacara',$array);
    }
    
    function save_op($isi){
        $this->db->insert("oportunity",$isi);
    }
    
    function update_op($id,$array){
        $this->db->where("idop",$id);	
        $this->db->update('oportunity',$array);
    }
    
    function cek_op(){
        $q = $this->db->query("SELECT * FROM `oportunity`");
        return $q->num_rows();
    }
    
    function get_op(){
        $q = $this->db->query("SELECT * FROM `oportunity`");
        return $q->result();
    }
    
    //google maps table kasus
    function get_kasus_map(){
        $q = $this->db->query(
            "SELECT m.`city_name`,m.`lat`,m.`long`,m.`city_id`,COUNT(*) AS jumlah 
            FROM `".$this->table."` AS k 
            INNER JOIN `".$this->tbl_city."` AS m ON k.`dk_kota`=m.`city_id` 
            GROUP BY m.`city_id`");
        return $q->result();
    }
    
    function get_all_propinsi(){
        $q = $this->db->query("SELECT * FROM `master_state`");
        return $q->result();
    }
    
    function insert_case($data){
        if( empty($data) ) return false;
        if( $this->db->insert($this->table, $data) ) {
            $id = $this->db->insert_id();
            return $id;
        };
        return false;
    }
    
    function insert_case_type($data){
        if( empty($data) ) return false;
        if( $this->db->insert($this->table_jk, $data) ) return true;
        return false;
    }
    
    function insert_case_saksi($data){
        if( empty($data) ) return false;
        if( $this->db->insert($this->table_sak, $data) ) return true;
        return false;
    }
    
    function update_case_tl($data, $id){
        if( empty($id) ) return false;
        if( empty($data) ) return false;
        if( $this->db->update($this->table, $data, array('id_kasus' => $id)) ) return true;
        return false;
    }
    
    function select_column_with_condition($column,$condition){
        $this->db->select($column);
        $this->db->where($condition);
        $this->db->from($this->table." A");
        return $this->db->get();
    }
    
    function select_column_jenis_kasus_with_condition($column,$condition){
        $this->db->select($column);
        $this->db->where($condition);
        $this->db->from($this->table_jk." A");
        return $this->db->get();
    }
}
/* End of file model_kasus.php */
/* Location: ./application/models/model_kasus.php */
